import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { ActivatedRoute } from '@angular/router';

@Injectable({
    providedIn: 'root'
})
export class LastUrlService {
    private last_url = new BehaviorSubject('');
    constructor() { }

    setURL(url: string) {
        this.last_url.next(url);
    }

    getURL(): Observable<string> {
        return this.last_url;
    }
}

export function GetLastURL(route: ActivatedRoute): string {
    let url: string = '';
    for (let r = route.snapshot; r; r = r.firstChild) {
        url = r.url.toString();
    }
    return url;
}
